<%@ include file="../import_page.jsp" %>
<%
	//login checking
	if(!loginedChecking(session, UsersType.staff)) {
		//user don't login
		//redirect to home page
		response.sendRedirect(URL_HOMEPAGE);
		return;
	}
	
	//select unit check
	if(!selectUnitCheck(session)) {
		//if user didn't select an Unit
		//redirtect to select page
		response.sendRedirect(URL_SELECT_UNIT);
		return;
	}
	
	//intput parament
	int acId = -1;
	String acIdStr = request.getParameter(PAR_ASSIGNMENT_ID);
	try {
		if(isEmptyString(acIdStr))
			throw new Exception("No parament input");
		acId = Integer.parseInt(acIdStr);
		if(acId < 1)
			throw new Exception("Incorrect assignment ID");
	} catch (Exception err) {
		//if fail to get parament, go back
		response.sendRedirect(URL_VIEW_ASSIGNMENT);
		return;
	}
	
	//intput parament
	String submitByStr = request.getParameter(PAR_SUBMIT_BY);
	Users submitBy = null;
	try {
		if(isEmptyString(submitByStr))
			throw new Exception("No parament input");
		
		UserControl uCon = new UserControl();
		submitBy = uCon.getUser(submitByStr);
		uCon.closeDBConnection();
	} catch (Exception err) {
		//if fail to get parament, go back
		response.sendRedirect(URL_VIEW_ASSIGNMENT);
		return;
	}
	
	Units selectUnit = (Units)session.getAttribute(SESSION_SELECT_UNIT);
	String errMsg = null;
	
	AssignmentCollector ac = null;
	ArrayList<DetailResult> listDr = null;
	SubmitAssignment sa = null;
	BigDecimal totalMark = new BigDecimal(0);
	//get assignment, detail result
	try {
		AssignmentsControl assCon = new AssignmentsControl();
		ResultControl rCon = new ResultControl();
		SubmitAssignmentControl saCon = new SubmitAssignmentControl();
		ac = assCon.getAssignment(acId);
		sa = saCon.getSubmited(acId, submitBy.getId());
		listDr = rCon.getDetailResult(acId, submitBy.getId());
		assCon.closeDBConnection();
		rCon.closeDBConnection();
		saCon.closeDBConnection();
	} catch (Exception err) {
		errMsg = err.toString();
	}
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Marking Assignment - <%= ac.getName() %></title>
<style type="text/css">
<!--
div.MsoNormal {
	mso-style-unhide: no;
	mso-style-qformat: yes;
	mso-style-parent: "";
	margin-top: 0in;
	margin-right: 0in;
	margin-bottom: 10.0pt;
	margin-left: 0in;
	line-height: 115%;
	mso-pagination: widow-orphan;
	font-size: 11.0pt;
	font-family: "Calibri", "sans-serif";
	mso-ascii-font-family: Calibri;
	mso-ascii-theme-font: minor-latin;
	mso-fareast-font-family: ????;
	mso-fareast-theme-font: minor-fareast;
	mso-hansi-font-family: Calibri;
	mso-hansi-theme-font: minor-latin;
	mso-bidi-font-family: "Times New Roman";
	mso-bidi-theme-font: minor-bidi;
}

li.MsoNormal {
	mso-style-unhide: no;
	mso-style-qformat: yes;
	mso-style-parent: "";
	margin-top: 0in;
	margin-right: 0in;
	margin-bottom: 10.0pt;
	margin-left: 0in;
	line-height: 115%;
	mso-pagination: widow-orphan;
	font-size: 11.0pt;
	font-family: "Calibri", "sans-serif";
	mso-ascii-font-family: Calibri;
	mso-ascii-theme-font: minor-latin;
	mso-fareast-font-family: ????;
	mso-fareast-theme-font: minor-fareast;
	mso-hansi-font-family: Calibri;
	mso-hansi-theme-font: minor-latin;
	mso-bidi-font-family: "Times New Roman";
	mso-bidi-theme-font: minor-bidi;
}

p.MsoNormal {
	mso-style-unhide: no;
	mso-style-qformat: yes;
	mso-style-parent: "";
	margin-top: 0in;
	margin-right: 0in;
	margin-bottom: 10.0pt;
	margin-left: 0in;
	line-height: 115%;
	mso-pagination: widow-orphan;
	font-size: 11.0pt;
	font-family: "Calibri", "sans-serif";
	mso-ascii-font-family: Calibri;
	mso-ascii-theme-font: minor-latin;
	mso-fareast-font-family: ????;
	mso-fareast-theme-font: minor-fareast;
	mso-hansi-font-family: Calibri;
	mso-hansi-theme-font: minor-latin;
	mso-bidi-font-family: "Times New Roman";
	mso-bidi-theme-font: minor-bidi;
}

p.MsoNormal1 {
	mso-style-unhide: no;
	mso-style-qformat: yes;
	mso-style-parent: "";
	margin-top: 0in;
	margin-right: 0in;
	margin-bottom: 10.0pt;
	margin-left: 0in;
	line-height: 115%;
	mso-pagination: widow-orphan;
	font-size: 11.0pt;
	font-family: "Calibri", "sans-serif";
	mso-ascii-font-family: Calibri;
	mso-ascii-theme-font: minor-latin;
	mso-fareast-font-family: ????;
	mso-fareast-theme-font: minor-fareast;
	mso-hansi-font-family: Calibri;
	mso-hansi-theme-font: minor-latin;
	mso-bidi-font-family: "Times New Roman";
	mso-bidi-theme-font: minor-bidi;
}

p.MsoNormal11 {
	mso-style-unhide: no;
	mso-style-qformat: yes;
	mso-style-parent: "";
	margin-top: 0in;
	margin-right: 0in;
	margin-bottom: 10.0pt;
	margin-left: 0in;
	line-height: 115%;
	mso-pagination: widow-orphan;
	font-size: 11.0pt;
	font-family: "Calibri", "sans-serif";
	mso-ascii-font-family: Calibri;
	mso-ascii-theme-font: minor-latin;
	mso-fareast-font-family: ????;
	mso-fareast-theme-font: minor-fareast;
	mso-hansi-font-family: Calibri;
	mso-hansi-theme-font: minor-latin;
	mso-bidi-font-family: "Times New Roman";
	mso-bidi-theme-font: minor-bidi;
}
-->
</style>
</head>

<body>
<%if(isEmptyString(errMsg)) {%>
<table width="100%" border="1">
	<tbody>
		<tr>
			<td width="40%"><strong>Unit (Unit Code)</strong></td>
			<td><%=selectUnit.getName() %> (<%=selectUnit.getId() %>)</td>
		</tr>
		<tr>
			<td><strong>Assignment Name</strong></td>
			<td><%= ac.getName() %></td>
		</tr>
		<tr>
			<td><strong>Student Name (ID) </strong>
			</td>
			<td><%=submitBy.getName() %> (<%=submitBy.getId() %>)</td>
		</tr>

		<tr>
			<td><strong>Submit Time (Deadline)</strong></td>
			<td><%=formatDateTime(sa.getSubmitTime()) %> (<%=formatDateTime(ac.getDeadline()) %>)</td>
		</tr>
		<tr>
			<td><strong>File</strong></td>
<%
	String fileText = "(None)";
	if(!isEmptyString(sa.getFileName())) {
		fileText = "<a href=\""+ addParmeterToUrl(URL_DOWNLOAD_ASSIGNMENT, PAR_ASSIGNMENT_ID, Integer.toString(ac.getId()))+ "\">"+ sa.getFileName()+ "</a>";
	}
%>
			<td><%=fileText %></td>
		</tr>
<%
	Iterator<DetailResult> ldrI = listDr.iterator();
	while(ldrI.hasNext()) {
		DetailResult dr = ldrI.next();
		totalMark = totalMark.add(dr.getMark());
%>
<tr>
			<td rowspan="2"><p class="MsoNormal1" style="margin-bottom: 0in; margin-bottom: .0001pt; line-height: normal; mso-element: frame; mso-element-frame-hspace: 9.0pt; mso-element-wrap: around; mso-element-anchor-horizontal: margin; mso-element-top: 35.15pt; mso-height-rule: exactly">
					<strong>Criteria <%=dr.getMsOrder() %>: <%=dr.getName() %></strong>
				</p>
				<p class="MsoNormal1" style="margin-bottom: 0in; margin-bottom: .0001pt; line-height: normal; mso-element: frame; mso-element-frame-hspace: 9.0pt; mso-element-wrap: around; mso-element-anchor-horizontal: margin; mso-element-top: 35.15pt; mso-height-rule: exactly">
					<strong>Criteria <%=dr.getMsOrder() %> Detail:</strong>
				</p>
				<p class="MsoNormal1" style="margin-bottom: 0in; margin-bottom: .0001pt; line-height: normal; mso-element: frame; mso-element-frame-hspace: 9.0pt; mso-element-wrap: around; mso-element-anchor-horizontal: margin; mso-element-top: 35.15pt; mso-height-rule: exactly">
					<strong><%= muiliteLineString(dr.getCriteria()) %></strong></p>
				<p></p>
			</td>
			<td>Mark: <%=dr.getMark() %> / <%=dr.getFullMark() %></td>
		</tr>
		<tr>
			<td>Feedback:<br />
				<%= muiliteLineString(dr.getFeedback()) %>
			</td>
		</tr>
<%
	}
%>
	<tr>
			<td>Total Mark</td>
			<td><%= totalMark %> / <%=ac.getFullMark() %></td>
		</tr>
		
	</tbody>
</table>
<%} else { %>
<p class="MsoNormal" style='tab-stops: 119.7pt'><%= errMsg %></p>
<%} %>
</body>
</html>